package com.xqit.ydzhkt.common.config.webscoket;

/**
 * Created by Janus on 2020/6/3
 *
 */
import com.xqit.ydzhkt.common.response.HttpResult;
import com.xqit.ydzhkt.common.response.ResultCodeEnum;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * WebSocketController
 * @author i
 */
@RestController
public class DemoController {

    @GetMapping("index")
    public HttpResult<String> index(){
        return HttpResult.success("请求成功");
    }

    @RequestMapping("/push/{toUserId}")
    public HttpResult<String> pushToWeb(String message, @PathVariable String toUserId){
        //message参数

        //发送自定义消息
        boolean b = WebSocketServer.sendInfo(message, toUserId);

        return (b == true) ? HttpResult.success(message) : HttpResult.failure(ResultCodeEnum.SEND_MESSAGE_ERROR);

    }
}